def up_tri(n=12):
    for j in range(1,n+1):
        for i in range(n,0,-1):
            sep = len(str(i))
            print("{0:>{1}}".format("",sep),end=' ') if i > j else print(i,end=' ')
        print()
up_tri()

def down_tri(n=12):
    for j in range(0,n):
        for i in range(n,0,-1):
            sep = len(str(i))
            print("{0:>{1}}".format("",sep),end=' ') if n-i <j else print(i,end=' ')
        print()
down_tri()

# 经过老师提醒后，将代码进行高效优化
def up_tri(n=12):
    tail = [str(i) for i in range(n, 0, -1)]
    tail_p = ' '.join(tail)
    width = len(tail_p)
    for i in range(n,0,-1):
        cur = tail[i-1:]
        cur_p = ' '.join(cur)
        cur_width = width - len(cur_p)
        print(cur_width*' ',cur_p,sep = "")
        
def down_tri(n=12):
    head = [str(i) for i in range(n, 0, -1)]
    head_p = ' '.join(head)
    width = len(head_p)
    for i in range(1,n+1):
        cur = head[i-1:]
        cur_p = ' '.join(cur)
        cur_width = width - len(cur_p)
        print(cur_width*' ',cur_p,sep = "")

arg = input(">>")
up_tri(int(arg))
print('-'*(int(arg)*3))
down_tri(int(arg))

#精简代码 使用字符串切片 合并函数

def triangle_t(n):
    tail = ' '.join([str(i) for i in range(n+1, 0, -1)])
    width = len(tail)
    for j in range(width):
        if tail[width-j-1] == ' ':
            print(' ' * (width-j-3) ,tail[-j:])
    print("-"*width)
    for j in range(len(tail)):
        if tail[j] == ' ':
            print(' ' * (j-2) ,tail[j+1:])

triangle_t(15)


# 完成的不错
